import Vue from 'vue'
import VueRouter from 'vue-router'
import BaiduMap from 'vue-baidu-map'
// import PhotoSharing from '../components/photosharing/PhotoSharing.vue'
// import PhotoInfo from '../components/photosharing/PhotoInfo.vue'
const PhotoSharing = () => import(/* webpackChunkName: "goop_photo" */ '../components/photosharing/PhotoSharing.vue')
const PhotoInfo = () => import(/* webpackChunkName: "goop_photo" */ '../components/photosharing/PhotoInfo.vue')

// import GoodsList from '../components/goods/GoodsList.vue'
// import GoodsInfo from '../components/goods/GoodsInfo.vue'
// import GoodsRecommend from '../components/goods/GoodsRecommend.vue'
const GoodsList = () => import(/* webpackChunkName: "groop_goods" */ '../components/goods/GoodsList.vue')
const GoodsInfo = () => import(/* webpackChunkName: "groop_goods" */ '../components/goods/GoodsInfo.vue')
const GoodsRecommend = () => import(/* webpackChunkName: "groop_goods" */ '../components/goods/GoodsRecommend.vue')
// import CallMap from '../components/map/Map.vue'
const CallMap = () => import(/* webpackChunkName: "map_search_add" */ '../components/map/Map.vue')
const Search = () => import(/* webpackChunkName: "map_search_add" */ '../components/search/Search.vue')
const Addition = () => import(/* webpackChunkName: "map_search_add" */ '../components/search/Addition.vue')
// import Search from '../components/search/Search.vue'
// import Addition from '../components/search/Addition.vue'
// import Login from '../components/login/Login.vue'
// import Register from '../components/login/Register.vue'
const Login = () => import(/* webpackChunkName: "login_reg" */ '../components/login/Login.vue')
const Register = () => import(/* webpackChunkName: "login_reg" */ '../components/login/Register.vue')
// import Category from '../components/category/Category.vue'
// import CategorySelect from '../components/category/CategorySelect.vue'
const Category = () => import(/* webpackChunkName: "groop_category" */ '../components/category/Category.vue')
const CategorySelect = () => import(/* webpackChunkName: "groop_category" */ '../components/category/CategorySelect.vue')
// import Vip from '../components/myvip/Vip.vue'
// import Order from '../components/myvip/Order.vue'
const Vip = () => import(/* webpackChunkName: "vip_order" */ '../components/myvip/Vip.vue')
const Order = () => import(/* webpackChunkName: "vip_order" */ '../components/myvip/Order.vue')
// import NewsList from '../components/news/NewsList.vue'
// import NewsInfo from '../components/news/NewsInfo.vue'
const NewsList = () => import(/* webpackChunkName: "groop_news" */ '../components/news/NewsList.vue')
const NewsInfo = () => import(/* webpackChunkName: "groop_news" */ '../components/news/NewsInfo.vue')

// import Home from '../components/Home.vue'
// import Homepage from '../components/home/Homepage.vue'
// import ShopCart from '../components/ShopCart.vue'
const Home = () => import(/* webpackChunkName: "home_homepage_shopcart" */ '../components/Home.vue')
const Homepage = () => import(/* webpackChunkName: "home_homepage_shopcart" */ '../components/home/Homepage.vue')
const ShopCart = () => import(/* webpackChunkName: "home_homepage_shopcart" */ '../components/ShopCart.vue')

Vue.use(BaiduMap, {
  ak: 'eT3pN0pBV6UnPY6bStZ8kR23rB5KUnQx'
})

Vue.use(VueRouter)

const routes = [
  { path: '/', redirect: '/home' },
  { path: '/homepage', component: Homepage },
  { path: '/cart', component: ShopCart },
  { path: '/contact', component: CallMap },
  { path: '/login', component: Login },
  { path: '/register', component: Register },
  { path: '/order', component: Order },
  { path: '/home',
    component: Home,
    redirect: '/homepage',
    children: [
      { path: '/news', component: NewsList },
      { path: '/newsinfo', component: NewsInfo },
      { path: '/photosharing', component: PhotoSharing },
      { path: '/photoinfo', component: PhotoInfo },
      { path: '/goods', component: GoodsList },
      { path: '/goodsinfo', component: GoodsInfo },
      { path: '/goodsrecommend', component: GoodsRecommend },
      { path: '/search', component: Search },
      { path: '/addition', component: Addition },
      { path: '/category', component: Category },
      { path: '/categoryselect', component: CategorySelect },
      { path: '/vip', component: Vip }
    ] }
]

const router = new VueRouter({
  routes
})

router.beforeEach((to, from, next) => {
  if (to.path !== '/vip') return next()
  const tokenStr = window.localStorage.getItem('token')
  if (!tokenStr) return next('/login')
  next()
})

export default router
